import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const context = require.context('./modules', false, /\.js$/)
let configRoutes = []
context.keys().forEach(key => {
  console.log(context(key))
  configRoutes = configRoutes.concat(context(key).default)
})

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  ...configRoutes
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if (to.path === '/') {
    next()
  } else {
    next()
  }
})

export default router
